//
//  PictureViewController.m
//  BeanTrip
//
//  Created by dlios on 15-7-11.
//  Copyright (c) 2015年 PandaGroup. All rights reserved.
//

#import "PictureViewController.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define HEIGH ([UIScreen mainScreen].bounds.size.height/667)
#import "DetailPicturesViewController.h"
@interface PictureViewController ()

@end

@implementation PictureViewController
- (void)dealloc
{
    [_collectionView release];
    [_collectionViewFlow release];
    [_array release];
    [_toptitle release];
    [super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSMutableArray array];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.navigationController.navigationBar.translucent = NO;
    self.title = self.toptitle;
    self.tabBarController.tabBar.backgroundColor = [UIColor blackColor];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    // 方块大小
    flowLayout.itemSize = CGSizeMake(375 * WIDTH, 400 * HEIGH);
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    // 滑动方法
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    // 集合视图
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 50 * HEIGH, 375 * WIDTH, 550 * HEIGH) collectionViewLayout:(flowLayout)];
    self.collectionView.backgroundColor = [UIColor blackColor];
    self.collectionView.pagingEnabled = YES;
    
    self.collectionViewFlow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView.contentOffset = CGPointMake(375 * self.integer * WIDTH, 0);
    self.collectionView.pagingEnabled = YES;
    
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[PictureCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;

    //轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popAction)];
    [self.view addGestureRecognizer:tap];
}


- (void)popAction
{
    [self.navigationController popViewControllerAnimated:YES];

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    PictureCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    DetailPicturesModel *data = [[DetailPicturesModel alloc] init];
    data = [self.array objectAtIndex:indexPath.row];
    cell.dinnerData = data;
    return cell;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
